﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace ExFlash.Records
{
    public class ClipActions : ISwfSerializable, IList<ClipActionRecord>, IList
    {
        private readonly int _swfVersion;
        
        public ClipEventFlags AllEventFlags
        {
            get;
            private set;
        }

        public List<ClipActionRecord> ClipActionRecords
        {
            get;
            private set;
        }

        public ClipActions(int version)
        {
            _swfVersion = version;
        }
        
        #region ISwfSerializable Members

        public void SwfDeserialize(BinaryBitReader reader)
        {
            // Reserved. Always 0.
            reader.Position += 2;

            AllEventFlags = new ClipEventFlags(_swfVersion);
            AllEventFlags.SwfDeserialize(reader);

            ClipActionRecords = ClipActionAssistant.GetClipActions(reader, _swfVersion);
        }

        public void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IList<ClipActionRecord> Members

        public int IndexOf(ClipActionRecord item)
        {
            return ClipActionRecords.IndexOf(item);
        }

        public void Insert(int index, ClipActionRecord item)
        {
            throw new NotImplementedException();
        }

        public void RemoveAt(int index)
        {
            throw new NotImplementedException();
        }

        public ClipActionRecord this[int index]
        {
            get
            {
                return ClipActionRecords[index];
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion

        #region ICollection<ClipActionRecord> Members

        public void Add(ClipActionRecord item)
        {
            throw new NotImplementedException();
        }

        public void Clear()
        {
            throw new NotImplementedException();
        }

        public bool Contains(ClipActionRecord item)
        {
            return ClipActionRecords.Contains(item);
        }

        public void CopyTo(ClipActionRecord[] array, int arrayIndex)
        {
            ClipActionRecords.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return ClipActionRecords.Count; }
        }

        public bool IsReadOnly
        {
            get { return true; }
        }

        public bool Remove(ClipActionRecord item)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IEnumerable<ClipActionRecord> Members

        public IEnumerator<ClipActionRecord> GetEnumerator()
        {
            return ClipActionRecords.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion

        #region IList Members

        public int Add(object value)
        {
            throw new NotImplementedException();
        }

        public bool Contains(object value)
        {
            return ClipActionRecords.Contains((ClipActionRecord)value);
        }

        int IList.IndexOf(object value)
        {
            return ClipActionRecords.IndexOf((ClipActionRecord)value);
        }

        public void Insert(int index, object value)
        {
            throw new NotImplementedException();
        }

        public bool IsFixedSize
        {
            get { return false; }
        }

        public void Remove(object value)
        {
            throw new NotImplementedException();
        }

        object IList.this[int index]
        {
            get
            {
                return ClipActionRecords[index];
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion

        #region ICollection Members

        public void CopyTo(Array array, int index)
        {
            ClipActionRecords.CopyTo((ClipActionRecord[])array, index);
        }

        public bool IsSynchronized
        {
            get { return ((IList)ClipActionRecords).IsSynchronized; }
        }

        public object SyncRoot
        {
            get { return ((IList)ClipActionRecords).SyncRoot; }
        }

        #endregion
    }
}
